<template>
	<view class="normal-login-container">
		<view class="logo-content align-center justify-center flex">
			<!-- <image style="width: 100rpx;height: 100rpx;" :src="totalConfig.appInfo.logo" mode="widthFix">
			</image> -->
			<text class="title">动物识别</text>
		</view>
		<view class="login-form-content">
			<view class="input-item flex align-center">
				<view class="iconfont icon-user icon"></view>
				<input v-model="loginForm.username" class="input" type="text" style="height: 90rpx;" placeholder="请输入账号" maxlength="30" />
			</view>
			<view class="input-item flex align-center">
				<view class="iconfont icon-password icon"></view>
				<input v-model="loginForm.password" type="password" class="input" style="height: 90rpx;" placeholder="请输入密码" maxlength="20" />
			</view>
			<view class="action-btn">
				<button @click="handleLogin"  class="login-btn  round">登录</button>
				<view class="font4">
					<view class="" @click="tofindpwd">
						忘记密码
					</view>
					<view class="" @click="tozhuce">
						注册账号
					</view>
				</view>
			</view>
		</view>

		<!-- <view class="xieyi text-center" style="margin-bottom: 5px;">
			<text class="text-grey1">登录即代表同意</text>
			<text @click="handleUserAgrement" class="text-blue">《用户协议》</text>
			<text @click="handlePrivacy" class="text-blue">《隐私协议》</text>
		</view> -->

		<view class="xieyi text-center">
			<text class="text-grey1">版本号:v1.0.0</text>
		</view>
	</view>
</template>

<script>
  import { login, access_token } from '@/api/login'
	export default {
		data() {
			return {
				loginForm: {
					username:'',
					password: "",
					code: "",
				},
			}
		},
	
		created() {
			// this.getCode();
		},
		methods: {
			
			// 获取图形验证码
			getCode() {
				
			},
			// 登录方法
			async handleLogin() {
				if (this.loginForm.username === "") {
					uni.showToast({
						icon:'none',
						title:'请输入手机号'
					})
				} else if (this.loginForm.password === "") {
					uni.showToast({
						icon:'none',
						title:'请输入密码'
					})
				} else {
					this.pwdLogin()
				}
			},
			// 密码登录
			async pwdLogin() {
				let params = {
					username:this.loginForm.username,
					password:this.loginForm.password,
				}
				login(params).then(res => {
					console.log('denglu-1',res)
					uni.setStorageSync('token',res.token)
					uni.setStorageSync("currentName", this.loginForm.username)
					uni.showToast({
						icon:'none',
						title:'登录成功'
					})
					uni.switchTab({
						url:'/pages/index/index'
					})
					this.access_token();
				}).catch(msg => {
				})
				
			},
			// 登录成功后，处理函数
			loginSuccess(result) {
				
			},
			tofindpwd(){
				uni.navigateTo({
					url:'/pages/login/find'
				})
			},
			tozhuce(){
				uni.navigateTo({
					url:'/pages/login/region'
				})
			},
			access_token(){
				access_token().then(res => {
					uni.setStorageSync('access_token',res.data)
				})
			}
			
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}

	.normal-login-container {
		width: 100%;

		.logo-content {
			width: 100%;
			font-size: 21px;
			text-align: center;
			padding-top: 15%;

			image {
				border-radius: 4px;
			}

			.title {
				margin-left: 10px;
			}
		}

		.login-form-content {
			text-align: center;
			margin: 20px auto;
			margin-top: 15%;
			width: 80%;

			.input-item {
				margin: 20px auto;
				background-color: #f5f6f7;
				height: 45px;
				border-radius: 20px;

				.icon {
					font-size: 38rpx;
					margin-left: 10px;
					color: #999;
				}

				.input {
					width: 100%;
					font-size: 28rpx;
					line-height: 40rpx;
					text-align: left;
					padding-left: 30rpx;
					::v-deep .uni-input-input{
						line-height: 40rpx;
					}
				}

			}

			.login-btn {
				margin-top:80rpx;
				height:80rpx;
				line-height:80rpx;
				background-color: #4e98dc;
				color: #fff;
				border-radius: 45rpx;
				font-size: 30rpx;
			}

			.xieyi {
				color: #333;
				margin-top: 20px;
			}
		}

		.easyinput {
			width: 100%;
		}
	}

	.login-code-img {
		height: 45px;
	}
	.font4{
		width: 100%;
		margin-top: 30rpx;
		text-align: right;
		color: #4e98dc;
		text-decoration: underline;
		display: flex;
		justify-content: space-between;
	}
</style>